Leading Spaces and split()
am 19.08.2011 22:01:18 von Deane.Rothenmaier--===============1119999654==
Content-Type: multipart/alternative;
boundary="_000_115007D93766724DAE9F518846E121DE9399CFDMSS8MP 2MBwagreso_"
Content-Language: en-US
--_000_115007D93766724DAE9F518846E121DE9399CFDMSS8MP2MBwagre so_
Content-Transfer-Encoding: quoted-printable
Content-Type: text/plain; charset="us-ascii"
Greetings, O Wise Ones...
I'm trying to understand the behavior I'm getting from this code:
#!Perl
############################################################ ###############=
#####
# PROGRAM: array_test1.pl
############################################################ ###############=
#####
use strict;
use warnings;
my $string1 =3D "Windows XP Professional Service Pack 2 (build 2600) Hewlet=
t-Packard";
my $string2 =3D " Windows XP Professional Service Pack 2 (build =
2600) Hewlett-Packard ";
my @ary1;
my @ary2;
@ary1 =3D split( " ", $string1 );
my ($win_type1, $win_ver1, $svc_pack1, $win_build1);
$win_type1 =3D $ary1[1];
$win_ver1 =3D $ary1[2];
for ($win_type1) {
/XP/ && do {
$svc_pack1 =3D $ary1[5];
($win_build1 =3D $ary1[7]) =3D~ s{\)}{};
last;
};
}
print "Current Method...\n";
print "Type: \"$win_type1\", Version: \"$win_ver1\",\n";
print "Service Pack: \"$svc_pack1\", Build: \"$win_build1\"\n\n";
my ($win_type2, $win_ver2, $svc_pack2, $win_build2);
for ($string1) {
/XP/ && do {
($win_type2, $win_ver2, $svc_pack2, $win_build2) =3D (split( /\s+/, $=
string1 ))[1, 2, 5, 7];
last;
};
}
$win_build2 =3D~ s{\)}{};
print "Proposed Method...\n";
print "Type: \"$win_type2\", Version: \"$win_ver2\",\n";
print "Service Pack: \"$svc_pack2\", Build: \"$win_build2\"\n";
@ary1 =3D split( " ", $string1 );
$win_type1 =3D $ary1[1];
$win_ver1 =3D $ary1[2];
for ($win_type1) {
/XP/ && do {
$svc_pack1 =3D $ary1[5];
($win_build1 =3D $ary1[7]) =3D~ s{\)}{};
last;
};
}
print "\nFILE string:\n";
print "Current Method...\n";
print "Type: \"$win_type1\", Version: \"$win_ver1\",\n";
print "Service Pack: \"$svc_pack1\", Build: \"$win_build1\"\n\n";
for ($string2) {
/XP/ && do {
($win_type2, $win_ver2, $svc_pack2, $win_build2) =3D (split( /\s+/, $=
string2 ))[1, 2, 5, 7];
last;
};
}
$win_build2 =3D~ s{\)}{};
print "Proposed Method...\n";
print "Type: \"$win_type2\", Version: \"$win_ver2\",\n";
print "Service Pack: \"$svc_pack2\", Build: \"$win_build2\"\n";
############################################################ ###############=
#####
# PROGRAM OUTPUT:
############################################################ ###############=
#####
Current Method...
Type: "XP", Version: "Professional",
Service Pack: "2", Build: "2600"
Proposed Method...
Type: "XP", Version: "Professional",
Service Pack: "2", Build: "2600"
FILE string:
Current Method...
Type: "XP", Version: "Professional",
Service Pack: "2", Build: "2600"
Proposed Method...
Type: "Windows", Version: "XP",
Service Pack: "Pack", Build: "(build"
The red text illustrates the error (if such it be?). My SWAG is that the "n=
othing" between Perl's '^' anchor and the first space in $string2 is what's=
causing the problem. Can someone confirm this? Or provide me with the corr=
ect answer if I'm wrong?
Thanks!
Deane Rothenmaier
Programmer/Analyst - IT-StdCfg
Walgreens Corp.
2 Overlook Point #N51022D
MS 6515
Lincolnshire, IL 60069
224-542-5150
I will make sure that my doomsday device is up to code and properly grounde=
d. - Peter Anspach's list of 100 things to do when one becomes an Evil Over=
lord
--_000_115007D93766724DAE9F518846E121DE9399CFDMSS8MP2MBwagre so_
Content-Transfer-Encoding: quoted-printable
Content-Type: text/html; charset="us-ascii"
xmlns:m=3D"http://schemas.microsoft.com/office/2004/12/omml" xmlns=3D"http:=
//www.w3.org/TR/REC-html40">
>
Greetings, O Wise Ones…
I’m trying to understand the behavior I’=
m getting from this code:
#!Perl
####################################################=
############################
# PROGRAM: array_test1.pl
####################################################=
############################
use strict;
use warnings;
my $string1 =3D "Windows XP Professional Servic=
e Pack 2 (build 2600) Hewlett-Packard";
my $string2 =3D " =
Windows XP Professional Service Pack 2=
(build 2600) Hewlett-Packard ";
my @ary1;
my @ary2;
@ary1 =3D split( " ", $string1 );
my ($win_type1, $win_ver1, $svc_pack1, $win_build1);=
$win_type1 =3D $ary1[1];
$win_ver1 =3D $ary1[2];
for ($win_type1) {
/XP/ && do {
$svc_pack1 =3D $ary1[=
5];
($win_build1 =3D $ary=
1[7]) =3D~ s{\)}{};
last;
};
}
print "Current Method...\n";
print "Type: \"$win_type1\", Version:=
\"$win_ver1\",\n";
print "Service Pack: \"$svc_pack1\", =
Build: \"$win_build1\"\n\n";
my ($win_type2, $win_ver2, $svc_pack2, $win_build2);=
for ($string1) {
/XP/ && do {
($win_type2, $win_ver=
2, $svc_pack2, $win_build2) =3D (split( /\s+/, $string1 ))[1, 2, 5, 7];=
last;
};
}
$win_build2 =3D~ s{\)}{};
print "Proposed Method...\n";
p>
print "Type: \"$win_type2\", Version:=
\"$win_ver2\",\n";
print "Service Pack: \"$svc_pack2\", =
Build: \"$win_build2\"\n";
@ary1 =3D split( " ", $string1 );
$win_type1 =3D $ary1[1];
$win_ver1 =3D $ary1[2];
for ($win_type1) {
/XP/ && do {
$svc_pack1 =3D $ary1[=
5];
($win_build1 =3D $ary=
1[7]) =3D~ s{\)}{};
last;
};
}
print "\nFILE string:\n";
print "Current Method...\n";
print "Type: \"$win_type1\", Version:=
\"$win_ver1\",\n";
print "Service Pack: \"$svc_pack1\", =
Build: \"$win_build1\"\n\n";
for ($string2) {
/XP/ && do {
($win_type2, $win_ver=
2, $svc_pack2, $win_build2) =3D (split( /\s+/, $string2 ))[1, 2, 5, 7];=
last;
};
}
$win_build2 =3D~ s{\)}{};
print "Proposed Method...\n";
p>
print "Type: \"$win_type2\", Version:=
\"$win_ver2\",\n";
print "Service Pack: \"$svc_pack2\", =
Build: \"$win_build2\"\n";
####################################################=
############################
# PROGRAM OUTPUT:
####################################################=
############################
Current Method...
Type: "XP", Version: "Professional&qu=
ot;,
Service Pack: "2", Build: "2600"=
Proposed Method...
Type: "XP", Version: "Professional&qu=
ot;,
Service Pack: "2", Build: "2600"=
FILE string:
Current Method...
Type: "XP", Version: "Professional&qu=
ot;,
Service Pack: "2", Build: "2600"=
Proposed Method...
Type: "Windows",=
Version: "XP",
Service Pack: "Pack&q=
uot;, Build: "(build"
The red text illustrates the error (if such it be?).=
My SWAG is that the “nothing” between Perl’s ‘^=
217; anchor and the first space in $string2 is what’s causing the pro=
blem. Can someone confirm this? Or provide me with the correct answer
if I’m wrong?
Thanks!
Deane Rothenmaier
Programmer/Analyst – IT-StdCfg
Walgreens Corp.
2 Overlook Point #N51022D
MS 6515
Lincolnshire, IL 60069
224-542-5150
I will make sure that my doomsday device is up to co=
de and properly grounded. – Peter Anspach’s list of 100 things =
to do when one becomes an Evil Overlord
--_000_115007D93766724DAE9F518846E121DE9399CFDMSS8MP2MBwagre so_--
--===============1119999654==
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline
_______________________________________________
ActivePerl mailing list
ActivePerl@listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
--===============1119999654==--